<template>
    <div>
        <el-breadcrumb
            separator-class="el-icon-arrow-right"
            class="breadcrumb-base"
            style="line-height: 30px"
        >
            <el-breadcrumb-item>
                <!--:to="{ path: '/application' }"-->
                <i class="el-icon-edit"></i>
                <span>标注管理</span>
            </el-breadcrumb-item>
        </el-breadcrumb>
        <div class="main-container">
            <el-form
                ref="filterForm"
                :model="filterForm"
                label-width="80px"
                @submit.native.prevent
            >
                <el-row>
                    <el-col :span="17">
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="病理编号">
                                    <el-input
                                        class="filter-input filter-picker"
                                        size="mini"
                                        v-model="filterForm.pathologyId"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <div v-if="showExpansion">
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="患者姓名">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.name"
                                            clearable
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item label="取材部位">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.sampleBody"
                                            clearable
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-col>

                                <el-col :span="7">
                                    <el-form-item label="送检医生">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.sendDoctor"
                                            clearable
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="病区名称">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.wardName"
                                            clearable
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item label="床位号">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.bedId"
                                            clearable
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item
                                        label="取材脏器"
                                        prop="pathologyHaslet"
                                    >
                                        <el-select
                                            size="mini"
                                            clearable
                                            v-model="filterForm.sampleOrganId"
                                            placeholder="请选择取材脏器"
                                        >
                                            <el-option
                                                v-for="item in organDict"
                                                :key="item.value"
                                                :label="item.dicName"
                                                :value="item.dicCode"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="7">
                                    <el-form-item label="联系电话">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.sendDoctorTel"
                                            clearable
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item label="标本名称">
                                        <el-input
                                            class="filter-input filter-picker"
                                            size="mini"
                                            v-model="filterForm.specimenName"
                                            clearable
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7">
                                    <el-form-item label="标本类别">
                                        <el-select
                                            v-model="
                                                filterForm.specimenType
                                            "
                                            placeholder="请选择标本类别"
                                            size="mini"
                                            clearable
                                        >
                                            <el-option
                                                v-for="data in specimenCategoryList"
                                                :key="data.id"
                                                :label="data.name"
                                                :value="data.id"
                                            >
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </div>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item>
                            <div
                                class="expansion"
                                @click="toggleExpansion"
                            >
                                <font-awesome-icon
                                    v-if="!showExpansion"
                                    :icon="['fas', 'angle-down']"
                                >
                                </font-awesome-icon>
                                <font-awesome-icon
                                    v-else
                                    :icon="['fas', 'angle-up']"
                                >
                                </font-awesome-icon>
                            </div>
                            <el-button
                                type="primary"
                                size="mini"
                                @click="search"
                                style="margin-left: 13px"
                            >
                                搜索
                            </el-button>
                            <el-button
                                type="primary"
                                size="mini"
                                :loading="buttonExportStatus"
                                @click="exportPic"
                            >
                                导出
                            </el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div style="display: flex; justify-content: space-between">
                <div class="pathological-count">
                    病例:{{ pathologicalCount.cases }} 数字切片:{{
                        pathologicalCount.pathology
                    }}
                    标注数据:{{ pathologicalCount.annotation }}
                </div>
                <el-progress
                    v-show="progressPercentage > 0"
                    :percentage="progressPercentage"
                    style="width: 500px"
                ></el-progress>
            </div>
            <div class="content">
                <el-row
                    v-for="firstCycle in baseData"
                    :key="firstCycle.id"
                    style="margin: 25px auto"
                >
                    <el-col :span="6">
                        <el-row>
                            <el-col :span="2">
                                <div class="patient-detail-checkbox">
                                    <el-checkbox
                                        v-model="firstCycle.firstModelValue"
                                        @change="
                                            firstLevelClick(
                                                firstCycle.firstModelValue,
                                                firstCycle.id
                                            )
                                        "
                                    ></el-checkbox>
                                </div>
                            </el-col>
                            <el-col :span="22">
                                <div class="patient-detail-content">
                                    患者姓名:{{ firstCycle.name }},性别:{{
                                        firstCycle.sexName
                                    }},年龄:{{ firstCycle.age }}
                                </div>
                                <div class="patient-detail-content">
                                    住院号:{{
                                        firstCycle.hospitalizedNo
                                    }}，病区名称:{{ firstCycle.wardName }}
                                </div>
                                <div class="patient-detail-content">
                                    ,病理编号:{{ firstCycle.pathologyId }}床位号:{{ firstCycle.bedId }}
                                </div>

                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col
                        :span="18"
                        style="
                            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12),
                                0 0 6px rgba(0, 0, 0, 0.04);
                            padding: 10px;
                            margin: 0 auto;
                        "
                    >
                        <el-row
                            v-for="secondCycle in firstCycle.biopsyList"
                            :key="secondCycle.id"
                        >
                            <el-col
                                :span="9"
                                style="display: flex"
                            >
                                <el-checkbox
                                    v-model="secondCycle.secondModelValue"
                                    @change="
                                        secondLevelClick(
                                            secondCycle.secondModelValue,
                                            firstCycle.id,
                                            secondCycle.id
                                        )
                                    "
                                    style="vertical-align: top"
                                ></el-checkbox>
                                <div @click="exclude(secondCycle)">
                                    <img
                                        :src="
                                            imageServiceURL +
                                            secondCycle.labelUrl
                                        "
                                        style="width: 150px; height: 150px"
                                    />
                                    <img
                                        :src="
                                            imageServiceURL +
                                            secondCycle.previewUrl
                                        "
                                        style="width: 150px; height: 150px"
                                    />
                                </div>
                            </el-col>
                            <el-col
                                :span="15"
                                style="
                                    display: flex;
                                    flex-direction: row;
                                    flex-wrap: wrap;
                                "
                            >
                                <el-row
                                    v-for="thirdCycle in secondCycle.annotationsList2"
                                    :key="thirdCycle.id"
                                    style="margin: 5px 5px"
                                >
                                    <el-col :span="3">
                                        <el-checkbox
                                            v-model="thirdCycle.thirdModelValue"
                                            @change="
                                                thirdLevelClick(
                                                    firstCycle.id,
                                                    secondCycle.id,
                                                    thirdCycle.id
                                                )
                                            "
                                        ></el-checkbox>
                                    </el-col>
                                    <el-col :span="21">
                                        <div>
                                            <img
                                                :src="
                                                    imageServiceURL +
                                                    thirdCycle.imageUrl
                                                "
                                                style="
                                                    width: 100px;
                                                    height: 100px;
                                                "
                                            />
                                            <div style="
                                                    width: 120px;
                                                    height: 70px;
                                                    margin: 10px auto;
                                                    overflow: auto;
                                                    font-size: 12px;
                                                ">
                                                <div>
                                                    标注内容:{{
                                                        thirdCycle.remarkOne
                                                    }}
                                                </div>
                                                <div>
                                                    标注医生:{{
                                                        thirdCycle.createUserName
                                                    }}
                                                </div>
                                                <div>
                                                    审核医生:{{
                                                        thirdCycle.updateUserName
                                                    }}
                                                </div>
                                                <div>
                                                    标注时间:{{
                                                        thirdCycle.createTime
                                                    }}
                                                </div>
                                            </div>
                                            <div style="display: flex">
                                                <el-button
                                                    size="mini"
                                                    @click="
                                                        deleteAnnotation(
                                                            secondCycle.id,
                                                            thirdCycle.id
                                                        )
                                                    "
                                                >删
                                                </el-button>
                                                <el-button size="mini">核
                                                </el-button>
                                            </div>
                                        </div>
                                    </el-col>
                                </el-row>
                            </el-col>
                        </el-row>
                    </el-col>
                </el-row>
            </div>

            <el-row
                style="margin-top: 10px"
                align="right"
            >
                <el-pagination
                    @current-change="handleCurrentChange"
                    @size-change="handleSizeChange"
                    :current-page="0"
                    :page-sizes="pagination_page_sizes"
                    :page-size="filterForm.size"
                    :total="total"
                    style="text-align: center; margin-top: 12px"
                    layout="sizes, prev, pager, next, total"
                >
                </el-pagination>
            </el-row>
        </div>
    </div>
</template>

<script>
import { itemsPerPage } from '../../libs/util';
import { PAGINATION_PAGE_SIZES } from '@/client/consts/constant';

export default {
    name: 'pathologicalMarkManage',
    data() {
        return {
            pagination_page_sizes: PAGINATION_PAGE_SIZES,
            //下载进度
            progressPercentage: 0,
            //病理id列表
            pathologyIdList: [],
            twoDoctorInfo: [],
            // 所需字典对应表
            dictRequestMap: [
                {
                    code: 'checkCategory',
                    arrayKey: 'checkCategoryList',
                    // }, {
                    //   code: 'patientCategory',
                    //   arrayKey: 'patientCategoryList',
                },
                {
                    code: 'SexKind',
                    arrayKey: 'sexKindList',
                    // }, {
                    //   code: 'ageUnitKind',
                    //   arrayKey: 'ageUnitKindList',
                },
                {
                    code: 'specimenCategory',
                    arrayKey: 'specimenCategoryList',
                },
            ],
            checkCategoryList: [],
            sexKindList: [],
            organDict: [], // 取材脏器列表
            specimenCategoryList: [],

            createdRange: [],
            showExpansion: false,
            filterForm: {
                pathologyId: '',
                name: '',
                sampleOrganId: '',
                sendDoctor: '',
                wardName: '',
                bedId: '',
                sampleBody: '',
                sendDoctorTel: '',
                specimenName: '',
                specimenType: '',
                page: 0,
                size: itemsPerPage.get(),
            },
            total: 0,
            buttonExportStatus: false,
            imageServiceURL: process.env.ImageServiceURL,
            pathologicalCount: {
                cases: 1,
                pathology: 1,
                annotation: 1,
            },
            specimenCategoryOptions: [
                {
                    value: '前列腺穿刺',
                    label: '前列腺穿刺',
                },
                {
                    value: '肺部',
                    label: '肺部',
                },
                {
                    value: '胸水脱落细胞',
                    label: '胸水脱落细胞',
                },
            ],
            markStatusOptions: [
                {
                    value: '全部',
                    label: '全部',
                },
                {
                    value: '未审核',
                    label: '未审核',
                },
                {
                    value: '已审核',
                    label: '已审核',
                },
            ],
            baseData: [],
        };
    },
    mounted() {
        // 获取切片和标注数据
        this.requireData();
        // 获取字典数据
        this.dictionariesRequest();
        // 获取脏器数据
        this.getExamineOrganType();
    },
    methods: {
        async getExamineOrganType() {
            try {
                await this.$axios({
                    method: 'get',
                    url: '/PROXY-Remote/organs/listAllOrgans',
                }).then((res) => {
                    if (res && res.data.code === 200) {
                        res.data.data.forEach((element) => {
                            this.organDict.push({
                                dicName: element.name,
                                dicCode: element.id,
                            });
                        });
                    }
                });
            } catch (e) {
                console.log(`请求失败  ${e}`);
            }
        },

        //点击所有信息列表的分页
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            itemsPerPage.set(val);
            this.filterForm.size = val;
            this.requireData();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.filterForm.page = val - 1;
            this.requireData();
        },
        firstLevelClick(checkedState, firstLevelId) {
            for (let i = 0; i < this.baseData.length; i++) {
                if (this.baseData[i].id == firstLevelId) {
                    if (checkedState) {
                        for (
                            let j = 0;
                            j < this.baseData[i].biopsyList.length;
                            j++
                        ) {
                            this.$set(
                                this.baseData[i].biopsyList[j],
                                'secondModelValue',
                                true
                            );
                            for (
                                let k = 0;
                                k <
                                this.baseData[i].biopsyList[j].annotationsList2
                                    .length;
                                k++
                            ) {
                                this.$set(
                                    this.baseData[i].biopsyList[j]
                                        .annotationsList2[k],
                                    'thirdModelValue',
                                    true
                                );
                            }
                        }
                    } else {
                        for (
                            let j = 0;
                            j < this.baseData[i].biopsyList.length;
                            j++
                        ) {
                            this.$set(
                                this.baseData[i].biopsyList[j],
                                'secondModelValue',
                                false
                            );
                            for (
                                let k = 0;
                                k <
                                this.baseData[i].biopsyList[j].annotationsList2
                                    .length;
                                k++
                            ) {
                                this.$set(
                                    this.baseData[i].biopsyList[j]
                                        .annotationsList2[k],
                                    'thirdModelValue',
                                    false
                                );
                            }
                        }
                    }
                }
            }
        },
        secondLevelClick(checkedState, firstLevelId, secondLevelId) {
            for (let i = 0; i < this.baseData.length; i++) {
                if (this.baseData[i].id == firstLevelId) {
                    //对第二级的操作
                    const newArr = this.baseData[i].biopsyList.filter(
                        (arrItem) => arrItem.secondModelValue == true
                    );
                    if (newArr.length == this.baseData[i].biopsyList.length) {
                        this.$set(this.baseData[i], 'firstModelValue', true);
                    } else {
                        this.$set(this.baseData[i], 'firstModelValue', false);
                    }
                    for (
                        let j = 0;
                        j < this.baseData[i].biopsyList.length;
                        j++
                    ) {
                        //对第三级的操作
                        if (
                            this.baseData[i].biopsyList[j].id == secondLevelId
                        ) {
                            if (checkedState) {
                                for (
                                    let k = 0;
                                    k <
                                    this.baseData[i].biopsyList[j]
                                        .annotationsList2.length;
                                    k++
                                ) {
                                    this.$set(
                                        this.baseData[i].biopsyList[j]
                                            .annotationsList2[k],
                                        'thirdModelValue',
                                        true
                                    );
                                }
                            } else {
                                for (
                                    let k = 0;
                                    k <
                                    this.baseData[i].biopsyList[j]
                                        .annotationsList2.length;
                                    k++
                                ) {
                                    this.$set(
                                        this.baseData[i].biopsyList[j]
                                            .annotationsList2[k],
                                        'thirdModelValue',
                                        false
                                    );
                                }
                            }
                        }
                    }
                }
            }
        },
        thirdLevelClick(firstLevelId, secondLevelId, thirdLevelId) {
            for (let i = 0; i < this.baseData.length; i++) {
                if (this.baseData[i].id == firstLevelId) {
                    for (
                        let j = 0;
                        j < this.baseData[i].biopsyList.length;
                        j++
                    ) {
                        if (
                            this.baseData[i].biopsyList[j].id == secondLevelId
                        ) {
                            for (
                                let k = 0;
                                k <
                                this.baseData[i].biopsyList[j].annotationsList2
                                    .length;
                                k++
                            ) {
                                if (
                                    this.baseData[i].biopsyList[j]
                                        .annotationsList2[k].id == thirdLevelId
                                ) {
                                    const newArr = this.baseData[i].biopsyList[
                                        j
                                    ].annotationsList2.filter(
                                        (arrItem) =>
                                            arrItem.thirdModelValue == true
                                    );
                                    if (
                                        newArr.length ==
                                        this.baseData[i].biopsyList[j]
                                            .annotationsList2.length
                                    ) {
                                        this.$set(
                                            this.baseData[i].biopsyList[j],
                                            'secondModelValue',
                                            true
                                        );
                                        //对第二级的操作
                                        const secondNewArr = this.baseData[
                                            i
                                        ].biopsyList.filter(
                                            (arrItem) =>
                                                arrItem.secondModelValue == true
                                        );
                                        if (
                                            secondNewArr.length ==
                                            this.baseData[i].biopsyList.length
                                        ) {
                                            this.$set(
                                                this.baseData[i],
                                                'firstModelValue',
                                                true
                                            );
                                        } else {
                                            this.$set(
                                                this.baseData[i],
                                                'firstModelValue',
                                                false
                                            );
                                        }
                                    } else {
                                        this.$set(
                                            this.baseData[i].biopsyList[j],
                                            'secondModelValue',
                                            false
                                        );
                                        this.$set(
                                            this.baseData[i],
                                            'firstModelValue',
                                            false
                                        );
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },

        search() {
            this.requireData();
        },
        toggleExpansion() {
            this.showExpansion = !this.showExpansion;
        },
        async exportPic() {
            let that = this;
            let secondIndex = 0;
            let thirdIndex = 0;
            this.baseData.forEach((i) => {
                i.biopsyList.forEach((j) => {
                    if (j.secondModelValue == true) {
                        secondIndex++;
                    }
                    j.annotationsList2.forEach((k) => {
                        if (k.thirdModelValue == true) {
                            thirdIndex++;
                        }
                    });
                });
            });
            if (secondIndex > 0 || thirdIndex > 0) {
                that.buttonExportStatus = true;
                that.progressPercentage = 0;
                let currentSecondIndex = 0;
                let currentThirdIndex = 0;
                await this.baseData.forEach((i) => {
                    i.biopsyList.forEach((j) => {
                        if (j.secondModelValue == true) {
                            currentSecondIndex++;
                            this.svsExport(
                                i.name,
                                i.pathologyId,
                                j.targetPath,
                                currentSecondIndex,
                                secondIndex,
                                currentThirdIndex,
                                thirdIndex
                            );
                        }
                        j.annotationsList2.forEach((k) => {
                            if (k.thirdModelValue == true) {
                                currentThirdIndex++;
                                let row = i.name + i.pathologyId;
                                let text =
                                    '标注内容:' +
                                    k.remarkOne +
                                    ';' +
                                    '标注医生:' +
                                    k.createUserName +
                                    ';' +
                                    '审核医生:' +
                                    k.updateUserName +
                                    ';' +
                                    '标注时间:' +
                                    k.createTime;
                                this.aninationExport(
                                    row,
                                    k.imageUrl,
                                    k,
                                    currentSecondIndex,
                                    secondIndex,
                                    currentThirdIndex,
                                    thirdIndex
                                ); //导出标注图片
                                this.exportRaw(row, text); //导出标注文本
                            }
                        });
                    });
                    this.progressPercentage =
                        ((currentSecondIndex + currentThirdIndex) /
                            (secondIndex + thirdIndex)) *
                        100;
                });
            } else {
                this.$message.info('请选择导出的内容');
            }
        },

        svsExport(
            name,
            pathologyId,
            item,
            currentSecondIndex,
            secondIndex,
            currentThirdIndex,
            thirdIndex
        ) {
            let _this = this;
            let fileSvs = item.split('/');
            let url = `${this.pathologyServiceURL}/download/${fileSvs[3]}`;
            let first = url.lastIndexOf('.'); //取到文件名开始到最后一个点的长度
            let nameLength = url.length; //取到文件名长度
            let fileSuffix = url.substring(first + 1, nameLength); //截取获得后缀名
            const x = new XMLHttpRequest();
            x.open('GET', url, true);
            x.responseType = 'blob';
            x.onload = function (e) {
                // 会创建一个 DOMString，其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
                const mUrl = window.URL.createObjectURL(x.response);
                const a = document.createElement('a');
                a.href = mUrl;
                a.download = name + pathologyId + '.' + fileSuffix;
                a.click();
                if (secondIndex === currentSecondIndex) {
                    _this.buttonExportStatus = false;
                }
            };
            x.send();
        },
        aninationExport(row, item, k, currentThirdIndex, thirdIndex) {
            let url = this.imageServiceURL + item;
            let fType = 'png';
            this.download(url, row, fType);
            // this.progressPercentage = (currentSecondIndex+currentThirdIndex)/(secondIndex+thirdIndex)*100;
        },
        download(src, row, fType) {
            //row.ITEMNAME为文件名称，src为文件存储地址            　　　　　　　　if (this.isImageInChromeNotEdge(fType)) {//判断是否为chrome里的图片
            if (this.isImageInChromeNotEdge(fType)) {
                //判断是否为chrome里的图片
                this.ImgtodataURL(src, row, fType);
            } else {
                this.downloadNormalFile(src, row);
            }
        },
        isImageInChromeNotEdge(fType) {
            let bool = false;
            if (
                window.navigator.userAgent.indexOf('Chrome') !== -1 &&
                window.navigator.userAgent.indexOf('Edge') === -1
            ) {
                (fType === 'jpg' ||
                    fType === 'gif' ||
                    fType === 'png' ||
                    fType === 'bmp' ||
                    fType === 'jpeg' ||
                    fType === 'svg') &&
                    (bool = true);
            }
            return bool;
        },
        downloadNormalFile(src, filename) {
            var link = document.createElement('a');
            link.setAttribute('download', filename);
            link.href = src;
            document.body.appendChild(link); //添加到页面中，为兼容Firefox浏览器
            link.click();
            document.body.removeChild(link); //从页面移除
        },
        ImgtodataURL(url, filename, fileType) {
            this.getBase64(url, fileType, (_baseUrl) => {
                // 创建隐藏的可下载链接
                var eleLink = document.createElement('a');
                eleLink.download = filename;
                eleLink.style.display = 'none';
                // 图片转base64地址
                eleLink.href = _baseUrl;
                // 触发点击
                document.body.appendChild(eleLink);
                eleLink.click();
                // 然后移除
                document.body.removeChild(eleLink);
            });
        },
        getBase64(url, fileType, callback) {
            //通过构造函数来创建的 img 实例，在赋予 src 值后就会立刻下载图片
            var Img = new Image(),
                dataURL = '';
            Img.src = url;
            Img.setAttribute('crossOrigin', 'Anonymous');
            Img.onload = function () {
                //要先确保图片完整获取到，这是个异步事件
                var canvas = document.createElement('canvas'), //创建canvas元素
                    width = Img.width, //确保canvas的尺寸和图片一样
                    height = Img.height;
                canvas.width = width;
                canvas.height = height;
                canvas.getContext('2d').drawImage(Img, 0, 0, width, height); //将图片绘制到canvas中
                dataURL = canvas.toDataURL('image/' + fileType); //转换图片为dataURL
                callback ? callback(dataURL) : null;
            };
        },
        //导出数据为txt的方法
        exportRaw(name, data) {
            var urlObject = window.URL || window.webkitURL || window;
            var exportBlob = new Blob([data]);
            var saveLink = document.createElement('a');
            saveLink.href = urlObject.createObjectURL(exportBlob);
            saveLink.download = name;
            this.fakeClick(saveLink);
        },
        fakeClick(obj) {
            var ev = document.createEvent('MouseEvents');
            ev.initMouseEvent(
                'click',
                true,
                false,
                window,
                0,
                0,
                0,
                0,
                0,
                false,
                false,
                false,
                false,
                0,
                null
            );
            obj.dispatchEvent(ev);
        },
        // 请求字典信息
        dictionariesRequest() {
            this.dictRequestMap.forEach((map) => {
                this.$axios({
                    method: 'GET',
                    url: '/PROXY-Remote/dicts/list',
                    params: {
                        code: map.code,
                        page: 0,
                        size: 99,
                    },
                }).then((res) => {
                    if (res && res.data.code === 200) {
                        this[map.arrayKey] = _.clone(res.data.data);

                        if (map.code === 'SexKind') {
                            this[map.arrayKey].push({
                                id: '',
                                name: '全部',
                            });
                        }
                    }
                });
            });
        },

        //请求数据
        requireData() {
            try {
                this.$axios({
                    method: 'POST',
                    url: '/PROXY-Remote/diagnosis/biopsyQuery',
                    data: this.filterForm,
                }).then((res) => {
                    if (res.data.code === 200) {
                        this.baseData = res.data.data;
                        this.total = Number(res.data.pageInfo.total);
                        this.pathologicalCount.cases = Number(
                            res.data.pageInfo.total
                        );
                        this.pathologicalCount.pathology = Number(
                            res.data.biopsyCount
                        );
                        this.pathologicalCount.annotation = Number(
                            res.data.annotationsCount
                        );
                        console.log('res.data', res.data);
                        for (let i = 0; i < this.baseData.length; i++) {
                            this.$set(
                                this.baseData[i],
                                'firstModelValue',
                                false
                            );
                            this.pathologyIdList.push(
                                this.baseData[i].pathologyId
                            );
                            for (
                                let j = 0;
                                j < this.baseData[i].biopsyList.length;
                                j++
                            ) {
                                this.$set(
                                    this.baseData[i].biopsyList[j],
                                    'secondModelValue',
                                    false
                                );
                                for (
                                    let k = 0;
                                    k <
                                    this.baseData[i].biopsyList[j]
                                        .annotationsList2.length;
                                    k++
                                ) {
                                    this.$set(
                                        this.baseData[i].biopsyList[j]
                                            .annotationsList2[k],
                                        'thirdModelValue',
                                        false
                                    );
                                }
                            }
                        }
                    }
                });
            } catch (e) {
                throw new Error(e);
            }
        },

        //跳转到切片浏览器
        exclude(val) {
            const { state } = this.$store;
            const { href } = this.$router.resolve({
                name: 'Viewer',
                path: '/Viewer',
                query: {
                    fileName: val.newFilename,
                    originFilename: val.originFilename,
                    pathologyId: val.pathologyId,
                    biopsyId: val.id,
                    authorization: this.$store.state.authorization,
                    userId: state.user.id,
                },
            });
            const width = window.screen.availWidth + 10;
            const height = window.screen.availHeight + 10;
            window.open(
                href,
                'doctorWorkstation',
                `location=no,width=${width},height=${height}`
            );
        },
        //删除标注
        deleteAnnotation(biopsyId, annotationId) {
            this.$confirm('此操作将永久删除该标注, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    try {
                        this.$axios({
                            method: 'delete',
                            url: `/PROXY-Remote/annotations/biopsy/${biopsyId}/annotations/${annotationId}`,
                            data: {},
                        }).then(
                            (res) => {
                                if (res && res.data.code === 200) {
                                    this.$message.success('删除成功');
                                    this.requireData();
                                } else {
                                    this.$message.warning(res.data.message);
                                }
                            },
                            (err) => {
                                this.$message.warning(
                                    `删除失败  ${err.response.data.message}`
                                );
                            }
                        );
                    } catch (e) {
                        console.log('请求失败');
                    }
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除',
                    });
                });
        },
    },
};
</script>

<style scoped>
.manage-header {
    display: flex;
    justify-content: space-between;
}

.content {
    margin-top: 10px;
}

.patient-detail-checkbox {
    text-align: center;
}

.patient-detail-content {
    padding-right: 15px;
}

.expansion {
    width: 30px;
    height: 30px;
    display: inline;
    font-size: 28px;
    line-height: 30px;
    margin-top: 25px;
    vertical-align: middle;
    color: #10a1df;
    cursor: pointer;
}
</style>
